<%@ page language="java" contentType="text/xml; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="org.springframework.core.io.ClassPathResource"%>
<%@page import="org.springframework.beans.factory.xml.XmlBeanFactory"%>
<%@page import="com.zenika.zencontact.model.ContactDao"%>
<%@page import="java.util.List"%>
<%@page import="com.zenika.zencontact.model.Contact"%>
<%
	ClassPathResource res = new ClassPathResource(
			"applicationContext.xml");
	XmlBeanFactory factory = new XmlBeanFactory(res);
	ContactDao dao = (ContactDao) factory.getBean("jdbcContactDao");


	try {
		int active = 0;
		List<Contact> list = dao.find("");
		out.println("<contacts>");
		for (int i = 0; i < list.size(); i++) {
			if(list.get(i).isActive()){
				active = 1;
			}else{
				active = 0;
			}
			out.println("<contact id=\""+list.get(i).getId()+"\" active=\""+active+"\" category=\""+list.get(i).getCategory()+"\" firstname=\""+list.get(i).getFirstName()+"\" lastname=\""+list.get(i).getLastName()+"\" birthdate=\""+list.get(i).getBirthDate()+"\" email=\""+list.get(i).getEmail()+"\" language=\""+list.get(i).getLanguage()+"\" notes=\""+list.get(i).getNotes()+"\" />");
			
		}
		out.println("</contacts>");

	} catch (Exception e) {
		e.printStackTrace();
	};%>